package com.waypolice.manager.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.waypolice.manager.service.PermissionsService;
import com.waypolice.mapper.UpmsPermissionMapper;
import com.waypolice.mapper.UpmsRolePermissionMapper;
import com.waypolice.pojo.UpmsPermission;
import com.waypolice.pojo.UpmsPermissionExample;
import com.waypolice.pojo.UpmsRolePermission;
import com.waypolice.pojo.UpmsRolePermissionExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 资源(权限)接口实现类
 * @author wr
 *
 */
@Service
public class PermissionsServiceImpl implements PermissionsService {

	@Autowired
	private UpmsPermissionMapper upmsPermissionMapper;
	
	@Autowired
	private UpmsRolePermissionMapper upmsRolePermissionMapper;

	@Override
	public List<UpmsPermission> findAll() {
		UpmsPermissionExample upmsPermissionExample = new UpmsPermissionExample();
		return upmsPermissionMapper.selectByExample(upmsPermissionExample);
	}

	@Override
	public List<UpmsPermission> findByRoleId(Integer roleId) {
		UpmsRolePermissionExample upmsRolePermissionExample = new UpmsRolePermissionExample();
		UpmsRolePermissionExample.Criteria criteria = upmsRolePermissionExample.createCriteria();
		criteria.andRoleIdEqualTo(roleId);
		List<UpmsRolePermission> selectByExample = upmsRolePermissionMapper.selectByExample(upmsRolePermissionExample);

		List<UpmsPermission> list = new ArrayList<>();
		for (UpmsRolePermission upmsRolePermission : selectByExample) {
            Integer permissionId = upmsRolePermission.getPermissionId();
            UpmsPermission upmsPermission = upmsPermissionMapper.selectByPrimaryKey(permissionId);
            list.add(upmsPermission);

        }
		return list;
	}
}
